package com.weishu.system.service.impl;


import java.util.Date;
import java.util.List;
import java.util.UUID;


import com.weishu.system.domain.TSfContract;
import com.weishu.system.domain.TSfTermination;
import com.weishu.system.mapper.TSfContractMapper;
import com.weishu.system.mapper.TSfTerminationMapper;
import com.weishu.system.service.ITSfContractService;
import com.weishu.common.core.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2021-06-18
 */
@Service
public class TSfContractServiceImpl implements ITSfContractService
{
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TSfTerminationMapper tSfTerminationMapper;

    @Autowired
    private TSfContractMapper tSfContractMapper;


    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public TSfContract selectTSfContractById(Long id)
    {
        return tSfContractMapper.selectTSfContractById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tSfContract 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TSfContract> selectTSfContractList(TSfContract tSfContract)
    {

        return tSfContractMapper.selectTSfContractList(tSfContract);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tSfContract 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTSfContract(TSfContract tSfContract)
    {
        tSfContract.setCreateTime(DateUtils.getNowDate());
        int i = tSfContractMapper.insertTSfContract(tSfContract);
        if (i > 0) {
            TSfTermination tSfTermination = new TSfTermination();
            // 获取解约协议编号
            String housId = "";
            try {
                housId = UUID.randomUUID().toString();
            } catch (Exception e) {
                logger.info("-----收房解约合同编号获取失败-----");
                throw e;
            }
            tSfTermination.setSfTerminationNo(tSfContract.getSfContractNo());
            tSfTermination.setSfContractId(tSfContract.getId());
            tSfTermination.setBusinessId(tSfContract.getBusinessId());
            tSfTermination.setDeptId(tSfContract.getDeptId());
            tSfTermination.setHouseId(housId);
            tSfTermination.setHouseName(tSfContract.getHouseName());
            tSfTermination.setCqAddress(tSfContract.getCqAddress());
            tSfTermination.setHouseZsNo(tSfContract.getHouseZsNo());
            tSfTermination.setOwnerMobile(tSfContract.getOwnerMobile());
            tSfTermination.setSignUserMobile(tSfContract.getSignUserMobile());
            tSfTermination.setWyjgDate(tSfContract.getWyjgDate());
            tSfTermination.setTerminationType(tSfContract.getTerminationType());
            tSfTermination.setRealTerminationDate(tSfContract.getLeaseEndTime());


            tSfTermination.setInputUserId(1L);
            tSfTermination.setInputUserName("admin");
            tSfTermination.setUpdateUserid(1L);
            tSfTermination.setSfContractNo(tSfContract.getSfContractNo());
            tSfTermination.setInputUserId(tSfContract.getSfUserId());
            tSfTermination.setSignUserName(tSfContract.getSignUserName());
            tSfTermination.setCreateTime(new Date());
            tSfTermination.setDeptNo(tSfContract.getDeptNo());
            tSfTermination.setUpdateTime(new Date());
            tSfTermination.setOwnerName(tSfContract.getOwnerName());
            tSfTermination.setPremiseName(tSfContract.getPremiseName());
            tSfTermination.setTerminationType(tSfContract.getTerminationType());
            tSfTermination.setTerminationDate(tSfContract.getWyjgDate());
            tSfTermination.setAuditDate(new Date());
            tSfTermination.setInputDate(new Date());
            tSfTermination.setDelFlg(0);
            tSfTerminationMapper.insertTSfTermination(tSfTermination);
        }
        return i;
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tSfContract 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTSfContract(TSfContract tSfContract)
    {
        tSfContract.setUpdateTime(DateUtils.getNowDate());
        return tSfContractMapper.updateTSfContract(tSfContract);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteTSfContractByIds(Long[] ids)
    {
        return tSfContractMapper.deleteTSfContractByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteTSfContractById(Long id)
    {
        return tSfContractMapper.deleteTSfContractById(id);
    }

    @Override
    public List<TSfContract> selectTSOwnerList(TSfContract tSfContract) {
        return tSfContractMapper.selectTSOwnerList(tSfContract);
    }

    @Override
    public List<TSfContract> querylist(TSfContract tSfContract) {
        return tSfContractMapper.querylist(tSfContract);
    }
}
